<template>
	<view class="content">
		<scroll-view @scrolltolower="scrolltolower" scroll-y class="content flex-h-1">
			<!-- 一层循环年 -->
			<view class="footer" v-for="(item,index) in newList" :key="index">
				<view class="thisMonth_header">
					{{item[0].pay_year}}年
				</view>
				<!-- 一层循环账单数据 -->
				<view class="" v-for="(item1,index1) in item" :key="index1" @click="goFiveBilling(item1.pay_year,item1.pay_month)">
					<view class="p24 df">
						<view class="header_name1">
							{{item1.pay_month}}月账单
						</view>
						<view class="df_s">
							<view class="money_ones">
								{{item1.sum_money}}
							</view>
							<view class="ml10 mb2">
								<u-icon color="#8C8C8C" name="arrow-right" size="25rpx"></u-icon>
							</view>
						</view>
					</view>
					<view class="xian"></view>
				</view>
				</vie<u-loadmore :status="more"></u-loadmore>
			</view>
	</scroll-view>
	</view>
</template>

<script>
	import monthlyPaymentA from "@/api/monthlyPaymentA.js"
	export default {
		data() {
			return {
				list: [],
				newList: [],
				page: 1,
				more: 'loadmore',
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			// 获取初始化数据
			getList() {
				if (this.more == 'nomore') return;
				monthlyPaymentA
					.getHistoryOrder({})
					.then((res) => {
						if (res.code == 0) {
							this.list.push(...res.data);
							this.more =this.list.length >= res.data.totalCount ? 'nomore' : 'loadmore';
							let groupedArrays = this.list.reduce((acc, obj,index) => {
							  let pay_year = obj.pay_year;
							  if (!acc[pay_year]) {
							    acc[pay_year] = [];
							  }
							  obj.pay_year = pay_year;
							  acc[pay_year].push(obj);
							  return acc;
							}, {});
							let newIndex = 0;
							let newObj = {};
							Object.keys(groupedArrays).forEach(key => {
							  newObj[newIndex++] = groupedArrays[key];
							});
							this.newList=newObj 
						}
					});
			},
			// 触发底部
			scrolltolower() {
				this.page++;
				this.getList();
			},
			// 跳转本月订单
			goFiveBilling(pay_year,pay_month) {
				 uni.navigateTo({
				      url: `/monthlyPaymentA/fiveBilling/fiveBilling?time=${pay_year+'-'+pay_month}&month=${pay_month}`
				  });
			},
		}
	}
</script>

<style>
	.mb2{
		margin-bottom: 2rpx;
	}
	.mt3 {
		margin-top: 3rpx;
	}

	.ml10 {
		margin-left: 10rpx;
	}

	.df_s {
		display: flex;
		align-items: center;
	}

	.money_ones {
		font-weight: 400;
		font-size: 24rpx;
		color: #8C8C8C;
	}

	.thisMonth_header {
		padding: 24rpx;
		font-weight: 400;
		font-size: 30rpx;
		color: #8C8C8C;
	}

	.mt10 {
		margin-top: 10rpx;
	}

	.header_state {
		font-weight: 400;
		font-size: 24rpx;
		color: #8C8C8C;
	}

	.header_name1 {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 30rpx;
		color: #262626;
	}

	.p24 {
		padding: 0rpx 24rpx;
	}

	.df {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.content {
		min-height: 100vh;
		background-color: #F2F2F2;
		padding-top: 24rpx;
	}

	.xian {
		width: 654rpx;
		height: 2rpx;
		background: #F8F8F8;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		margin: 30rpx auto;
	}

	.footer {
		width: 702rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		margin: 0rpx auto;
	}
</style>